package org.pattern.builder.model;

import org.pattern.builder.builders.FullAutomaticPizzaOven;
import org.pattern.builder.builders.readers.PizzaPropertiesFileReader;

/**
 * Created by IntelliJ IDEA.
 * User: Administrator
 * Date: 16-11-2010
 * Time: 18:32:12
 * To change this template use File | Settings | File Templates.
 */
/** "Director" */
public class Cook {
	private FullAutomaticPizzaOven pizzaOven = new FullAutomaticPizzaOven();

    public Pizza buyHawaiianPizza() {        
        return constructPizza("Hawaiian",Pizza.class);
    }
    public Pizza buySpicyPizza() {
        return constructPizza("Spicy",XMLPizza.class);        
    }    

    public Pizza constructPizza(String name, Class type) {
        PizzaPropertiesFileReader fileReader = new PizzaPropertiesFileReader();
        fileReader.setFilename("app.properties");

        pizzaOven.useFilereader(fileReader)
                .typeToBuild(type)
                .useDoughType(PizzaPropertyNames.DOUGH_CROSS)
		        .useSauceType(PizzaPropertyNames.SAUCE_MILD)
                .addTopping(PizzaPropertyNames.TOPPING_HAM)
                .addTopping(PizzaPropertyNames.TOPPING_PEPPERONI)
                .callPizza(name);

        Pizza pizza = pizzaOven.bake();


        StringBuilder sb = new StringBuilder();
        sb.append("One ")
                .append(pizza.getName())
                .append(" pizza with ")
                .append(pizza.getDough()).append(" dough,")
                .append(pizza.getSauce()).append(" sauce and ")
                .append(pizza.getTopping()).append(" done sir.");
        System.err.println(sb.toString());
	    return pizza;
    }
}
